﻿using UnityEngine;
using System.Collections;

public class StartGame : MonoBehaviour
{

    // Use this for initialization
    public static bool gameStart = false;
    public float shipSpeed;
    public float MaxSpeed;
    public float Acceleration;
    private Ray ray;
    private RaycastHit hit;

    private Camera mycam;
    public static bool selectLevels = false;
	public float y = 4.6f,h = 12.5f,w = 3f;
	public Texture2D Lock;
	public GUIStyle stylin;// = new GUIStyle(GUI.skin.GetStyle("Button"));
    // Update is called once per frame
    void Start()
    {
        Camera[] cams = Camera.allCameras;
        foreach(Camera cam in cams)
        {
            if (cam != Camera.current)
            {
                mycam = cam;
            }
        }

        //Lock = (Texture2D)Resources.Load("Textures/Ships/lockme", typeof(Texture2D));
    }
    void Update()
    {
        if (gameStart)
        {
            if (shipSpeed < MaxSpeed)
                shipSpeed = shipSpeed + Acceleration * Time.deltaTime;
            transform.position = new Vector3(transform.position.x, transform.position.y, transform.position.z + shipSpeed * Time.deltaTime);
				
			  mycam.transform.parent = gameObject.transform;
           
            //mycam.transform.position = transform.position + new Vector3(-6.5f,1.086768f,-1.495359f);
            //	mycam.transform.parent= this;
            //mycam = transform.parent;
          

        }
		 if (transform.position.z > 70.0f)
            {
			 mycam.transform.parent = null;
                selectLevels = true;
                //Application.LoadLevel(1);
               // gameStart = false;
            }

    }
    void OnGUI()
    {
        GUIStyle stylinDisabled = GUI.skin.button;// = stylin;
        stylinDisabled.normal.textColor = new Color(66f, 66f, 66f);

        if (selectLevels)
        {
            //  Rect levelselect = new Rect(Screen.width / 2 - 10, Screen.height / 2 - 80, 150, 50);
       
			Rect diff = new Rect(Screen.width/2, Screen.height/y, Screen.width/w, Screen.height/h);
            diff = new Rect(diff.x - diff.width/2, diff.y, diff.width, diff.height);
			if (GUI.Button(new Rect(diff.x, diff.y, diff.width, diff.height), "Tutorial", stylin))
			{
				PlayerPrefs.SetString("Difficulty", "Tutorial");
				selectLevels = false;
				Application.LoadLevel(6);
			}
			if (GUI.Button(new Rect(diff.x, diff.y+ 1.5f*diff.height, diff.width, diff.height), "Easy", stylin))
            {
                PlayerPrefs.SetString("Difficulty", "Easy");
                selectLevels = false;
                Application.LoadLevel(1);
            }
            if (GUI.Button(new Rect(diff.x, diff.y + 3f * diff.height, diff.width, diff.height), "Normal", stylin))
            {
                PlayerPrefs.SetString("Difficulty", "Medium");
                selectLevels = false;
                Application.LoadLevel(1);
            }
            if (true)//PlayerPrefs.GetString("BeatGame") == "Yes")
            {

                if (GUI.Button(new Rect(diff.x, diff.y + 4.5f * diff.height, diff.width, diff.height), "Hard", stylin))
                {
                    PlayerPrefs.SetString("Difficulty", "Hard");
                    selectLevels = false;
                    Application.LoadLevel(1);
                }
                if (GUI.Button(new Rect(diff.x, diff.y + 6f * diff.height, diff.width, diff.height), "Boss", stylin))
                {
                    PlayerPrefs.SetString("Difficulty", "Boss");
                    selectLevels = false;
                    Application.LoadLevel(1);
                }
            }
            else
            {
                GUI.Button(new Rect(diff.x, diff.y + 4.5f * diff.height, diff.width, diff.height), "Hard", stylin);
                GUI.DrawTexture(new Rect(diff.x, diff.y + 4.5f * diff.height, diff.width, diff.height), Lock);
                GUI.Button(new Rect(diff.x, diff.y + 6.0f * diff.height, diff.width, diff.height), "Boss", stylin);
                GUI.DrawTexture(new Rect(diff.x, diff.y + 6.0f * diff.height, diff.width, diff.height), Lock);
            }
        }
    }
    void OnMouseUp()
    {
        if (GameObject.Find("lift").GetComponent<Moveoneway>() == null)
        {
            gameStart = true;
            TouchKit.removeAllGestureRecognizers();

            switch (gameObject.tag)
            {
                case "ThisIsSparta":
                    PlayerPrefs.SetString("PlayerShip", "ThisIsSparta");
                    break;

                case "B2Bomber":
                    PlayerPrefs.SetString("PlayerShip", "B2Bomber");
                    break;

                case "Goldy":
                    PlayerPrefs.SetString("PlayerShip", "Goldy");
                    //PlayerPrefs.SetInt("Currency", PlayerPrefs.GetInt("Currency") + 1000); //Currently doing in currency decide where is better
                    break;

                case "Regs":
                    PlayerPrefs.SetString("PlayerShip", "Regs");
                    break;
            }
        }
    }
}
